package com.jxc.jxc01.hch.service.Impl;

import com.jxc.jxc01.hch.dao.Impl.InventoryDaoImpl;
import com.jxc.jxc01.hch.dao.InventoryDao;
import com.jxc.jxc01.hch.entity.Inventory;
import com.jxc.jxc01.hch.entity.PageHelper;
import com.jxc.jxc01.hch.service.IInventoryService;

import java.text.SimpleDateFormat;
import java.util.Date;

public class IInventoryServiceImpl implements IInventoryService {
    InventoryDao inventoryDao = new InventoryDaoImpl();
    @Override
    public PageHelper<Inventory> list(PageHelper<Inventory> pageHelper) {
        inventoryDao.list(pageHelper);
        int pageCount = (pageHelper.getTotal()%pageHelper.getPageSize())==0?pageHelper.getTotal()/pageHelper.getPageSize():pageHelper.getTotal()/pageHelper.getPageSize()+1;
        pageHelper.setPageCount(pageCount);
        return pageHelper;
    }

    @Override
    public PageHelper<Inventory> query(PageHelper<Inventory> pageHelper, String username) {
        inventoryDao.query(pageHelper,username);
        int pageCount = (pageHelper.getTotal()%pageHelper.getPageSize())==0?pageHelper.getTotal()/pageHelper.getPageSize():pageHelper.getTotal()/pageHelper.getPageSize()+1;
        pageHelper.setPageCount(pageCount);
        return pageHelper;
    }

    @Override
    public int increase(Inventory inventory) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //接收时间日期
        String s = sdf.format(date);
        inventory.setCreationtime(s);
        return inventoryDao.increase(inventory);
    }

    /**
     * 修改字段
     * @param inventory
     * @return
     */
    @Override
    public int modify(Inventory inventory) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //接收时间日期
        String s = sdf.format(date);
        inventory.setModificationtime(s);
        return inventoryDao.modify(inventory);
    }

    @Override
    public int delete(int id) {
        return inventoryDao.delete(id);
    }
}
